package com.niit.entity;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hanli
 * @date 2025/3/4
 * @description TODO
 */
public class Test {

    public static void main(String[] args) {

          // 向上类型转换  自动发生的
//        Person person = new Student();
//        Student teacher = new Teacher();
//
//        List<String> list = new ArrayList<>();

//        Student student1 = new Student();
//        Student student2 = new Student("abcd");

        // 读取 bean 配置文件，并创建 ApplicationContext容器实例
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-beans.xml");

        // (Student) 向下类型转换   还原
        // new Student() --> Object 向上类型转换
        // Object obj = ctx.getBean("student");
        Student student1 = (Student) ctx.getBean("student");
        student1.setId(1001);

        Teacher teacher = (Teacher) ctx.getBean("teacher");

        // 反射 reflect
        Student student2 = ctx.getBean(Student.class);
        System.out.println("student2:"+student2.getId());

        University university = University.getInstance();

    }
}